﻿#include "frmmsg.h"
#include "ui_frmmsg.h"
#include "widget.h"
#include "FsGlobal.h"
#include "qevent.h"
FrmMsg::FrmMsg(QWidget *parent) :QWidget(parent), ui(new Ui::FrmMsg)
{
    ui->setupUi(this);
        this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);//去掉标题栏
    this->setAttribute(Qt::WA_TranslucentBackground, true);//设置窗口背景透明
    // 将窗口置顶
    this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
//    // 设置窗口透明度
//    this->setWindowOpacity(0.8);
    timer = new QTimer;
    connect(timer,&QTimer::timeout,this,&FrmMsg::showTime);   // 信号连接 每一秒执行一次槽函数
    showTime();
    timer->start(1000);
       ui->frame->installEventFilter(this);
}

FrmMsg::~FrmMsg()
{
    delete ui;
}

void FrmMsg::on_canclePBtn_clicked()
{
    countdownMain = -1;
    isCountdowning =false;
    this->hide();
}

void FrmMsg::showTime()
{
    int countdown =countdownMain;
    qDebug() << "msg" << countdown;
    QString countdownStr=QString::number(countdown);
    countdownStr +="秒后关机，请保存工作！";
    ui-> shutdownTimeLbl->setText(countdownStr);  // 设置标签内容
}

#define TITLE_HEIGHT 200


QPoint FrmMsg::last(0,0);
void FrmMsg::mousePressEvent(QMouseEvent *event)//判断鼠标点击时是否小于标题栏高度
{
    if(event->y()<TITLE_HEIGHT)
    {
        last = event->globalPos();//获取坐标
    }
}

void FrmMsg::mouseMoveEvent(QMouseEvent *event)//鼠标移动，实时修改窗口的坐标
{
    if(event->y()<TITLE_HEIGHT)
    {
        int dx = event->globalX() - last.x();
        int dy = event->globalY() - last.y();
        last = event->globalPos();
        this->move(this->x()+dx,this->y()+dy);
    }
}

void FrmMsg::mouseReleaseEvent(QMouseEvent *event)//鼠标释放
{
    if(event->y()<TITLE_HEIGHT)
    {
        int dx = event->globalX() - last.x();
        int dy = event->globalY() - last.y();
        this->move(this->x()+dx,this->y()+dy);
    }
}



void FrmMsg::on_delayPBtn_clicked()
{
    countdownMain += 60*10;
    this->hide();
}

